#include <iostream>
#include <vector>

using namespace std;

// 插入排序算法
vector<int> insertionSort(vector<int> arr) {
    int n = arr.size();
    for (int i = 1; i < n; i++) {
        int key = arr[i];
        int j = i - 1;
        while (j >= 0 && arr[j] > key) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = key;
    }
    return arr;
}

// 冒泡排序算法
vector<int> bubbleSort(vector<int> arr) {
    int n = arr.size();
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                swap(arr[j], arr[j + 1]);
            }
        }
    }
    return arr;
}

// 打印数组元素
void printArray(const vector<int>& arr) {
    int n = arr.size();
    for (int i = 0; i < n; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;
}

// 判断两个数组是否相等
bool compareArrays(const vector<int>& arr1, const vector<int>& arr2) {
    int n = arr1.size();
    if (n != arr2.size()) {
        return false;
    }
    for (int i = 0; i < n; i++) {
        if (arr1[i] != arr2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    vector<int> arr1 = {5, 2, 8, 4, 1};
    vector<int> arr2 = {5, 2, 8, 4, 1};

    cout << "Original Array: ";
    printArray(arr1);

    vector<int> sortedArr1 = insertionSort(arr1);
    vector<int> sortedArr2 = bubbleSort(arr2);

    cout << "Insertion Sorted Array: ";
    printArray(sortedArr1);

    cout << "Bubble Sorted Array: ";
    printArray(sortedArr2);

    if (compareArrays(sortedArr1, sortedArr2)) {
        cout << "Sorting Test Passed!" << endl;
    } else {
        cout << "Sorting Test Failed!" << endl;
    }

    return 0;
}
